package com.atguigu.springcloud.service.impl;

import com.alibaba.csp.sentinel.annotation.SentinelResource;
import com.alibaba.csp.sentinel.slots.block.BlockException;
import com.atguigu.springcloud.service.OrderService;
import org.springframework.stereotype.Service;

import java.util.Random;

/**
 * @author admin
 * @title: OrderServiceImpl
 * @projectName cloud2021
 * @description: TODO
 * @date 2021/12/8 13:35
 */
@Service
public class OrderServiceImpl implements OrderService {
    @Override
    @SentinelResource(value = "getOrder",blockHandler = "handleException")
    public String getOrder() {
        return String.valueOf(new Random().nextInt());
    }
    public String handleException(BlockException ex){
        return ex.getClass().getCanonicalName() + "\t 服务不可用";
    }
}
